"""
    2. 给你一个 n*m 的二维数组，每个元素保证递增，每列元素保证递增，
    试问如何找到某个数字，或者判断这个数字不存在。
"""

# ls = [[1, 2, 3, 7, 8, 9],
#       [4, 5, 6, 11, 13, 15],
#       [6, 8, 9, 13, 15, 18] ]
#
#
# def decide_colun(ls2, n):
#     count = ls2[0]
#     while n >= count:
#         for i in ls2:
#             if i == n:
#                 return True
#             else:
#                 count = i
#     return False
#
#
#
# def decide_group(ls, n):
#     for ls1 in ls:
#         if ls1[-1] > n > ls1[0]:
#             if decide_colun(ls1, n):
#                 return True
#         else:
#             return False
#
#
# print(decide_group(ls,10))

# 阶梯算法
ls = [[1, 2, 3, 7, 11, 13],
      [2, 5, 6, 11, 13, 15],
      [6, 8, 9, 13, 15, 18]]

m = 0
n = 0
count = len(ls[0])
# s = int(input('输入'))
s = 4
if s > ls[-1][-1] or s < ls[0][0]:
    print('不存在')
else:
    while True:
        if ls[m][n] > s and count > 0:
            count -= 1
        if n <= count:
            if ls[m][n] == s:
                print('存在')
                break
            else:
                n += 1
        else:
            m += 1
            n = 0
